package com.lancoo.cvas.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.lancoo.cvas.pojo.vo.GradeMajorTree;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 年级专业
 * 
 * @author liufeng
 * @email 1037383243@qq.com
 * @date 2023-12-04 11:54:00
 */
@Data
@TableName("major")
@Accessors(chain = true)
@ApiModel("专业信息")
public class Major implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 专业id
	 */

	@TableId(value = "major_id", type = IdType.AUTO)
	@ApiModelProperty("专业id")
	private Long majorId;
	/**
	 * 任务id
	 */
	@ApiModelProperty("任务id")
	private Integer taskId;
	/**
	 * 所属年级id
	 */
	@ApiModelProperty("所属年级id")
	private String gradeId;
	/**
	 * 所属年级名称
	 */
	@ApiModelProperty("所属年级名称")
	private String gradeName;
	/**
	 * 基础平台年级id
	 */
	@ApiModelProperty("基础平台年级id")
	private String baseMajorId;
	/**
	 * 专业名称
	 */
	@ApiModelProperty("专业名称")
	private String majorName;
	/**
	 * 所属校区id
	 */
	@ApiModelProperty("所属校区id")
	private String campusId;
	/**
	 * 所属校区名称
	 */
	@ApiModelProperty("所属校区名称")
	private String campusName;
	/**
	 * 主修学分上限
	 */
	@ApiModelProperty("主修学分上限")
	private Double creditLimitMain;
	/**
	 * 主修课程数上限
	 */
	@ApiModelProperty("主修课程数上限")
	private Integer courseLimitMain;
	/**
	 * 辅修学分上限
	 */
	@ApiModelProperty("辅修学分上限")
	private Double creditLimitMinor;
	/**
	 * 辅修课程数上限
	 */
	@ApiModelProperty("辅修课程数上限")
	private Integer courseLimitMinor;
	/**
	 * 上限设置 1未设置 2已设置
	 */
	@ApiModelProperty("上限设置")
	private Integer stateLimit;
	/**
	 * 1仅主修 2存在辅修
	 */
	@ApiModelProperty("1仅主修 2存在辅修")
	private Integer onlyMajor;
	/**
	 * 操作状态 0未开启  1已开启
	 */
	@ApiModelProperty("操作状态")
	private Integer isEnable;
	/**
	 * 删除标识：
0：未删除
1：删除
	 */
	@ApiModelProperty("删除标识")
	private Integer deleted;
	/**
	 * 
	 */
	private String reserve;

	public static List<GradeMajorTree> toGradeMajorTree(List<Major> majorList) {
		List<GradeMajorTree> res = new ArrayList<>();

		for (Major major : majorList) {
			String gradeId = major.getGradeId();
			String gradeName = major.getGradeName();

			GradeMajorTree gradeMajorTree = null;
			for (GradeMajorTree tree : res) {
				if (tree.getGradeId().equals(gradeId)){
					gradeMajorTree = tree;
					break;
				}
			}

			if (gradeMajorTree == null){
				gradeMajorTree = new GradeMajorTree();
				gradeMajorTree.setGradeId(gradeId);
				gradeMajorTree.setGradeName(gradeName);
//				gradeMajorTree.setSum(gradeMajorTree.getSum() + 1);
				res.add(gradeMajorTree);
			}
			gradeMajorTree.getMajors().add(major);
			gradeMajorTree.setSum(gradeMajorTree.getSum() + 1);
		}
		return res;
	}
}
